import React from 'react';
import { SafeAreaView, Text} from 'react-native';

class  App extends React.Component {
state = {
  data: 100
}

fun(){
  console.log(this.state)
}
//1.正确的写法 箭头函数
// fun=()=>{
//   console.log(this.state)
// }

//4.通过构造函数来绑定
  constructor(props: {} | Readonly<{}>) {
    super(props); // 修复的关键点：调用父类构造函数并传递 props
    this.fun = this.fun.bind(this);
  }
  render() {
    return (
      <SafeAreaView>
        <Text onPress={this.fun}>{this.state.data}</Text>
        {/**2.通过 bind 绑定this */}
        {/* <Text onPress={this.fun.bind(this)}>{this.state.data}</Text> */}
        {/**3.通过 匿名函数 绑定this */}
        {/* <Text onPress={()=>{this.fun()}}>{this.state.data}</Text> */}
      </SafeAreaView>
    )
  }
}
export default App;
